﻿using System;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
using System.Diagnostics;

namespace Notepad_Clone
{
    class AboutDialog:Window
    {
        public AboutDialog(Window owner)
        {
            Assembly asmbly = Assembly.GetExecutingAssembly();

            AssemblyTitleAttribute title = (AssemblyTitleAttribute)asmbly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false)[0];
            string strTitle = title.Title;

            AssemblyFileVersionAttribute version = (AssemblyFileVersionAttribute)asmbly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false)[0];
            string strVersion = version.Version.Substring(0, 3);

            AssemblyCopyrightAttribute copy = (AssemblyCopyrightAttribute)asmbly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false)[0];
            string strCopyright = copy.Copyright;

            this.Title = "About " + strTitle;
            this.ShowInTaskbar = false;
            this.SizeToContent = SizeToContent.WidthAndHeight;
            this.ResizeMode = ResizeMode.NoResize;
            this.Left = owner.Left + 96;
            this.Top = owner.Top + 96;

            StackPanel stackMain = new StackPanel();
            this.Content = stackMain;

            TextBlock txtblk = new TextBlock()
            {
                Text = strTitle + " Version " + strVersion,
                FontFamily = new FontFamily("Times New Roman"),
                FontSize = 32,
                FontStyle = FontStyles.Italic,
                Margin = new Thickness(24),
                HorizontalAlignment = HorizontalAlignment.Center
            };
            stackMain.Children.Add(txtblk);

            txtblk = new TextBlock()
            {
                Text = strCopyright,
                FontSize = 20,
                HorizontalAlignment = HorizontalAlignment.Center
            };
            stackMain.Children.Add(txtblk);

            Run run = new Run("www.joyssom.com");
            Hyperlink link = new Hyperlink(run);
            link.Click += this.LinkOnClick;
            txtblk = new TextBlock(link);
            txtblk.FontSize = 20;
            txtblk.HorizontalAlignment = HorizontalAlignment.Center;
            stackMain.Children.Add(txtblk);

            Button btn = new Button()
            {
                Content = "OK",
                IsDefault = true,
                IsCancel = true,
                HorizontalAlignment = HorizontalAlignment.Center,
                Margin = new Thickness(24)
            };
            btn.Click += this.OkOnClick;
            stackMain.Children.Add(btn);

            btn.Focus();
        }

        private void OkOnClick(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }

        private void LinkOnClick(object sender, RoutedEventArgs e)
        {
            Process.Start("http://www.joyssom.com");
        }
    }
}
